package br.ufpr.inf.formulario.web;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import br.ufpr.inf.formulario.AtividadeSolicitada;
import br.ufpr.inf.formulario.Solicitacao;

@RooWebScaffold(path = "solicitacaos", formBackingObject = Solicitacao.class)
@RequestMapping("/solicitacaos")
@Controller
public class SolicitacaoController {         @RequestMapping(method = RequestMethod.POST)
public String create(@Valid Solicitacao solicitacao, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("solicitacao", solicitacao);
        return "solicitacaos/create";
    }
    uiModel.asMap().clear();
    solicitacao.persist();
    
	uiModel.addAttribute("solicitacao", solicitacao);
	return "solicitacaos/create";
	

}

@RequestMapping(method = RequestMethod.PUT)
public String update(@Valid Solicitacao solicitacao, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("solicitacao", solicitacao);
        return "solicitacaos/update";
    }
    uiModel.asMap().clear();
    solicitacao.merge();
    
    AtividadeSolicitada atividadesolicitadas = new AtividadeSolicitada();
    uiModel.addAttribute("atividadeSolicitada", atividadesolicitadas);
    
	return "atividadesolicitadas/create";
}
}
